package com.tanhua.app.controller;

import com.tanhua.app.controllerservice.SoundService;
import com.tanhua.domain.vo.SoundVo;
import com.tanhua.domain.vo.UserHolder;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class SoundController {
    private final SoundService soundService;

    public SoundController(@Autowired SoundService soundService) {
        this.soundService = soundService;
    }

    @PostMapping(name = "发送一条传音",value = "/peachblossom")
    public ResponseEntity<String> send(@RequestPart("soundFile") MultipartFile soundFile) throws IOException {
        return soundService.send(soundFile, UserHolder.getUser().getId());
    }

    @GetMapping(name = "接收一条传音",value = "/peachblossom")
    public ResponseEntity<SoundVo> receive() {
        return soundService.receive(UserHolder.getUser().getId());
    }
}
